package org.academic.texteditor.gui.component;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.RenderingHints;

import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JLabel;

public class ActionButton extends JButton {

	private static final long serialVersionUID = -5436137492457347018L;

	private Paint paintBackground;
	
	public ActionButton() {
		super();
	}

	public ActionButton(Action a) {
		super(a);
	}

	public ActionButton(Icon icon) {
		super(icon);
	}

	public ActionButton(String text, Icon icon) {
		super(text, icon);
	}

	public ActionButton(String text) {
		super(text);
	}

	public Paint getPaintBackground() {
		if (paintBackground == null) {
			return getBackground();
		}
		return paintBackground;
	}

	public void setPaintBackground(Paint background) {
		this.paintBackground = background;
	}

	@Override
	public void paint(Graphics g) {
		Graphics2D g2d = (Graphics2D) g;
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
		        RenderingHints.VALUE_ANTIALIAS_ON);
		
		int width = getWidth();
		int height = getHeight();

		g2d.setPaint(getPaintBackground());
		g.fillRoundRect(0, 0, width, height, 20, 20);

		g2d.setPaint(getPaintBackground());
		JLabel label = new JLabel(getText());
		label.setHorizontalAlignment(JLabel.CENTER);
		label.setSize(width, height);
		label.setFont(getFont());
		label.setForeground(getForeground());
		label.paint(g);
	}
	
}
